package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.dao.ShopGoodsDao;
import com.hualan.dao.impl.ShopGoodsDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/sousuo")
public class sousuo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String goodsname = null;
        String shopname = null;
        String star = null;
        String end = null;
        int i = Integer.parseInt(req.getParameter("pageNum"));
        int j = Integer.parseInt(req.getParameter("pageSize"));
        if (req.getParameter("goodsName")!=null){
            goodsname =req.getParameter("goodsName");
        }
        if (req.getParameter("shopName")!=null) {
            shopname = req.getParameter("shopName");
        }

        if (req.getParameter("startTime")!=null){
            star =req.getParameter("startTime");
        }
        if (req.getParameter("endTime")!=null){
            end =req.getParameter("endTime");
        }

        ShopGoodsDao goodsDao = new ShopGoodsDaoImpl();

        try {
            resp.setContentType("text/html;charset=utf-8");
            resp.setCharacterEncoding("utf-8");
            Map<String,Object> map = new HashMap<>();
//            map.put("list", goodsDao.fenyegoodslist(i,j));
            map.put("list", goodsDao.sousuo(i,j,goodsname,shopname,star,end));

            map.put("int",goodsDao.allnum());
            String json = JSON.toJSONString(map);
            resp.getWriter().write(json);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);


    }
}
